/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package rfid;

import org.llrp.ltk.generated.enumerations.GetReaderConfigRequestedData;
import org.llrp.ltk.generated.enumerations.StatusCode;
import org.llrp.ltk.generated.messages.GET_READER_CONFIG;
import org.llrp.ltk.generated.messages.GET_READER_CONFIG_RESPONSE;
import org.llrp.ltk.net.LLRPConnection;
import org.llrp.ltk.types.UnsignedShort;

/**
 *
 * @author xandru
 */
public class RFIDUtils {
private static final int TIMEOUT_MS = 10000;

     public static void getReaderConfig(LLRPConnection reader)
    {
    GET_READER_CONFIG_RESPONSE response;
    try
    {
        GET_READER_CONFIG readerConfig = new GET_READER_CONFIG();

        // Request all config parameters.
        readerConfig.setRequestedData
            (new GetReaderConfigRequestedData
                (GetReaderConfigRequestedData.All));
        // Request configuration for all antennas and ports.
        readerConfig.setAntennaID(new UnsignedShort(0));
        readerConfig.setGPIPortNum(new UnsignedShort(0));
        readerConfig.setGPOPortNum(new UnsignedShort(0));

        // Send the message.
        response = (GET_READER_CONFIG_RESPONSE)
            reader.transact(readerConfig, TIMEOUT_MS);

        // Check if the we successfully
        // received the reader configuration.
        StatusCode status = response.getLLRPStatus().getStatusCode();
        if (status.equals(new StatusCode("M_Success")))
        {
            // Print out the reader config.
            System.out.println(response.toXMLString());
        }
        else
        {
            System.out.println("Error getting reader config.");
            System.exit(1);
        }
    }
    catch (Exception e)
    {
        System.out.println("Error getting reader config.");
        e.printStackTrace();
    }
}

}
